/**********************************************************************************
**
** Copyright (C) 2009 Jostein Bratlie
** Contact: jostein.bratlie@gmail.com | http://bratlie.info | http://episteme.hin.no
**
** This file is part of GMQtExt, a GMlib and Qt extension library
**
** GMQtExt is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** GMQtExt is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with GMQtExt.  If not, see <http://www.gnu.org/licenses/>.
**
**********************************************************************************/


#ifndef GLWIDGET_H
#define GLWIDGET_H


// Windows bugg
#include <gmOpenGL>

// Qt
#include <QGLWidget>

// GMlib
#include <gmWindow>



// Local Defines
#define SNAP 0.01

namespace GMQtExt {

  class GLWidget : public QGLWidget, public GMlib::GMWindow {
    Q_OBJECT
  public:
    GLWidget( QWidget *parent = 0 );
    ~GLWidget();

    void                      clear();
    virtual void              initScene();

    // *********************************
    // Derived GMlib::GMWindow functions
    bool                      toggleRun();

  public slots:
    void                      insert( GMlib::SceneObject *obj );
    void                      setSelectedObject( GMlib::SceneObject *obj );

  protected:

    void                      hidEventEdit();
    void                      hidEventReplotQuickHigh();
    void                      hidEventReplotQuickLow();
    void                      hidEventSelectObjTree( GMlib::SceneObject *obj );
    void                      hidEventToggleShadingMode();

    // ********************
    // Derived QT functions
    void                      glDraw();
    void                      initializeGL();
    void                      keyPressEvent( QKeyEvent* e );
    void                      keyReleaseEvent( QKeyEvent* e );
    void                      mouseDoubleClickEvent ( QMouseEvent* e );
    void                      mouseMoveEvent( QMouseEvent* e );
    void                      mousePressEvent( QMouseEvent* e );
    void                      mouseReleaseEvent( QMouseEvent* e );
    void                      paintEvent( QPaintEvent* e );
    void                      paintGL();
    void                      resizeGL( int w, int h );
    void                      timerEvent( QTimerEvent* qte );
    void                      wheelEvent( QWheelEvent* e );

    // *********************************
    // Derived GMlib::GMWindow functions
    void                      swapBuffers();

    int                       _timerID;
    bool                      _shaded;
    bool                      _move_border;

    int                       _hid_prevX, _hid_prevY;

  signals:
    void                      signActiveObjectChanged( GMlib::SceneObject* );

  }; // END class GLWidget

} // END namespace GMQtExt

#endif // GLWIDGET_H
